package com.njitweb.service.impl;

import com.njitweb.mapper.CategoryMapper;
import com.njitweb.exception.LoginException;
import com.njitweb.pojo.Category;
import com.njitweb.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryDao;
    @Override
    public void addCategory(Category category) {
        category.setCreatedDate(new Date(System.currentTimeMillis()));
        category.setUpdatedDate(new Date(System.currentTimeMillis()));
        System.out.println(category);
        categoryDao.addCategory(category);
    }

    @Override
    public List<Category> listCategory() {
        return  categoryDao.listCategory();
    }

    @Override
    public void deleteCategory(Integer id) {
        if (id==null){
            throw new LoginException("id不能为空");
        }
        categoryDao.deleteCategory(id);
    }

    @Override
    public Category getDetailCategory(Integer id) {
        return categoryDao.getDetailCategory(id);
    }

    @Override
    public void updateCategory(Category category) {
         categoryDao.updateCategory(category);
    }
}
